<template>
  <!-- 未安检户数/安检总户数/列表 -->
  <el-dialog
    v-el-drag-dialog
    title="安检计划"
    :visible.sync="visible"
    width="1024px"
    append-to-body
    @close="reset"
  >
    <lb-table
      ref="lbTable"
      v-loading="$loadingPlugin.fetchData"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      pagination
      :immediate-fetch="false"
      :total="tableData.total"
      custom-column
      @fetch="fetchData"
    />
  </el-dialog>
</template>

<script>
  import { gasCheckPlanClientList } from '@/api'

  export default {
    name: 'households-list',
    components: {
    },
    data() {
      return {
        visible: false,
        temp: {},
        tableData: {
          total: 0,
          data: [],
          column: [
            {
              prop: 'csmCode',
              label: '客户编号'
            },
            {
              prop: 'csmName',
              label: '客户名称'
            },
            {
              prop: 'csmPhone',
              label: '客户电话'
            },
            {
              prop: 'orgName',
              label: '所属机构'
            },
            {
              prop: 'csmAddress',
              label: '地址'
            },
            {
              prop: 'checkUser',
              label: '安检人'
            },
            {
              prop: 'warnLevel',
              label: '隐患等级',
              render: (h, { row }) => {
                var obj = {
                  0: '无隐患',
                  1: '一般隐患',
                  2: '严重隐患',
                  3: '隐患',
                  4: 'level4',
                  5: 'level5'
                }
                return <span>{obj[row.warnLevel]}</span>
              }
            }
          ]
        }
      }
    },
    methods: {
      async open(temp) {
        this.temp = temp
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          this.$nextTick(() => {
            this.$refs.lbTable.fetch({ currentPage: 1 })
          })
        })
      },
      reset() {
        this.visible = false
        this.temp = {}
      },
      async fetchData({ currentPage, pageSize }) {
        console.log('this.temp', this.temp)
        const res = await gasCheckPlanClientList({
          ...this.temp,
          pageIndex: currentPage,
          pageSize
        })
        this.tableData.data = res.data.rows
        console.log('this.tableData.data', this.tableData.data)
        if (currentPage === 1) this.tableData.total = res.data.total
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
